# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=python-threadloop
pkgver=1.0.2
pkgrel=7
pkgdesc="Tornado IOLoop Backed Concurrent Futures"
url="https://github.com/unhashable/threadloop"
license=('MIT')
arch=('any')
depends=('python-tornado')
makedepends=('python-setuptools')
checkdepends=('python-pytest')
source=("https://github.com/unhashable/threadloop/archive/$pkgver/$pkgname-$pkgver.tar.gz"
        tornado-5.patch)
sha512sums=('f6a95d01174cf3dacafda4ebc7f4f8efa1217675004949ce0565441a40aa9867be33f23cd78ce8de83de992b8bb654db34ff49568804790bcf27efa7c0b3643d'
            '4b9c0f77e4cc004854588d1fcfcd46dabdd57055dd866c18ce9d29b9f746a0abcaa790f727e92e13b4e422f8c0fd82856db6cf4b7a2dca9ed33ad7403bd44998')

prepare() {
  cd threadloop-$pkgver
  patch -p1 -i ../tornado-5.patch
}

build() {
  cd threadloop-$pkgver
  python setup.py build
}

check() {
  cd threadloop-$pkgver
  # Deselected tests: deadlocks
  pytest -v --deselect tests/threadloop/test_threadloop.py::test_plain_function_exception_propagates \
            --deselect tests/threadloop/test_threadloop.py::test_plain_function_exception_contains_exc_info
}

package() {
  cd threadloop-$pkgver
  python setup.py install --root="$pkgdir" --optimize=1

  # It's only present when tests are enabled, so adding -f
  local python_version=$(python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
  rm -rf "$pkgdir"/usr/lib/python${python_version}/site-packages/tests

  install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}
